package com.xbongbong.pro.statistic.model.impl;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.pro.domain.dao.ChartDrillDao;
import com.xbongbong.pro.domain.entity.ChartDrillEntity;
import com.xbongbong.pro.statistic.model.ChartDrillModel;
import com.xbongbong.saas.constant.ParameterConstant;
import com.xbongbong.saas.constant.StringConstant;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author bomfish
 */
@Service("chartDrillModel")
public class ChartDrillModelImpl implements ChartDrillModel {
    @Resource
    private ChartDrillDao dao;

    @Override
    public Integer insert(ChartDrillEntity entity) {
        return dao.insert(entity);
    }

    @Override
    public Integer save(ChartDrillEntity entity) {
        if(entity.getId() == null || entity.getId().equals(0L)) {
            return insert(entity);
        }
        return update(entity);
    }

    @Override
    public void insertBatch(List<ChartDrillEntity> list) {
        dao.insertBatch(list);
    }

    @Override
    public void updateBatch(List<ChartDrillEntity> entityList, String corpid) {
        dao.updateBatch(entityList, corpid);
    }

    @Override
    public List<ChartDrillEntity> findEntitys(Map<String, Object> param) {
        return dao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return dao.getEntitysCount(param);
    }

    @Override
    public Integer update(ChartDrillEntity entity) {
        return dao.update(entity);
    }

    @Override
    public ChartDrillEntity getByKey(Long key, String corpid) {
        return dao.getByKey(key, corpid);
    }

    @Override
    public ChartDrillEntity getByChartId(String corpid, Integer statisticsType, Long chartId){
        return dao.getByChartId(corpid, statisticsType, chartId);
    }

    @Override
    public List<ChartDrillEntity> findByChartId(String corpid, Integer statisticsType, List<Long> chartIdIn) {
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put(ParameterConstant.CORPID, corpid);
        param.put(StringConstant.STATISTICS_TYPE, statisticsType);
        param.put(ParameterConstant.DEL, chartIdIn);
        param.put("chartIdIn", chartIdIn);
        return findEntitys(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return dao.findEntitys(param);
    }
}
